import { defineStore } from 'pinia';

interface IUserInfo {
    name: string;
    age: number;
    userInfo: object;
    token: string;
    tenantInfo: object;
    tenant: string;
}

const userStore = defineStore({
    id: 'user',
    state: (): IUserInfo => ({
        name: '',
        age: 0,
        userInfo: {},
        token: '',
        tenantInfo: {},
        tenant: ''
    }),
    actions: {
        updateUserInfo(userInfo: any): void {
            this.userInfo = userInfo
            this.name = userInfo.username;
        },
        updateToken(token:string):void{
            this.token = token
        }
    },
    storage: {
        enabled: true,
        storage: sessionStorage
    }
});

export default userStore